﻿using System;
using FikriKibar.Common.Enums;
using FikriKibar.Common.Helpers;
using FikriKibar.Common.Logging.Abstract;
using log4net;
using log4net.Config;


namespace FikriKibar.Common.Logging
{
    public class FikriKibarLogManager : IFikriKibarLogManager
    {
        public FikriKibarLogManager()
        {
            XmlConfigurator.Configure();
        }

        public void Log(Type type, string message, LogOptions logOptions)
        {
            var logConfiguration = ConfigurationHelper.GetAppSetting("Use" + logOptions + "Log");
            switch (logOptions)
            {
                case LogOptions.Debug:
                    if (logConfiguration.ConvertToBoolean())
                    {
                        LogManager.GetLogger(type).Debug(message);
                    }
                    break;

                case LogOptions.Error:
                    if (logConfiguration.ConvertToBoolean())
                    {
                        LogManager.GetLogger(type).Error(message);
                    }
                    break;

                case LogOptions.Warn:
                    if (logConfiguration.ConvertToBoolean())
                    {
                        LogManager.GetLogger(type).Warn(message);
                    }
                    break;

                case LogOptions.Info:
                    if (logConfiguration.ConvertToBoolean())
                    {
                        LogManager.GetLogger(type).Info(message);
                    }
                    break;

                case LogOptions.Fatal:
                    if (logConfiguration.ConvertToBoolean())
                    {
                        LogManager.GetLogger(type).Fatal(message);
                    }
                    break;

                default:
                    if (logConfiguration.ConvertToBoolean())
                    {
                        LogManager.GetLogger(type).Info(message);
                    }
                    break;
            }
        }


    }
}
